<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
  <th:block th:include="include :: header('选择接收人')" />
</head>
<body class="gray-bg">
<div class="container-div">
  <div class="row">
    <div class="col-sm-12 search-collapse">
      <form id="notice-form">
        <input type="hidden" name="recipient" id="recipient" th:value="${notice.recipient}">
        <div class="select-list">
          <ul>
            <li>
              姓名：<input type="text" name="userName"/>
            </li>
            <li class="hidden">
              身份证号：<input type="text" name="cardNo"/>
            </li>
            <li>
              手机号：<input type="text" name="phonenumber"/>
            </li>
            <li>
              <label>所属机构：</label>
              <div class="input-group" style="width: 250px;margin-left: 65px;">
                <input name="deptId" type="hidden" id="deptId" th:value="${deptId}"/>
                <input name="deptName" onclick="selectDeptTree()" id="deptName" th:value="${deptName}" type="text" placeholder="请选择所属部门" class="form-control" readonly style="background-color: #FFFFFF;">
                <span class="input-group-addon"><i class="fa fa-close" id="clearBtn"></i>&nbsp;|&nbsp;<i class="fa fa-search"></i></span>
              </div>
            </li>
            <li>
              <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
              <a class="btn btn-warning btn-rounded btn-sm" onclick="resetForm()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
            </li>
          </ul>
        </div>
      </form>
    </div>

    <div class="col-sm-12 select-table table-striped">
      <table id="bootstrap-table"></table>
    </div>
  </div>
</div>
<th:block th:include="include :: footer" />
<script th:inline="javascript">
  var editFlag = [[${@permission.hasPermi('system:notice:edit')}]];
  var prefix = ctx + "system/notice";

  $(function() {
    var options = {
      url: prefix + "/user/list",
      rememberSelected: true,
      modalName: "选择接收人",
      columns: [{
        checkbox: true,
        formatter: function (value, row, index) {
            if (row.checked == 0) {
                return value;
            } else {
                return {checked: true};
            }
          }
      },
        {
          field: 'userId',
          title: '用户ID'
        },
        {
          field: 'loginName',
          title: '登录名称',
          sortable: true
        },
        {
          field: 'userName',
          title: '用户名称'
        },
        {
          field: 'dept.deptName',
          title: '部门'
        },
        {
          field: 'partyDate',
          title: '入党日期',
          formatter: function (value, row, index) {
            if (value == null || value == '') {
              return '-';
            }
            return $.common.dateFormat(value, 'yyyy-MM-dd');
          }
        },
        {
          field: 'cardNo',
          title: '身份证号',
          visible: false
        },
        {
          field: 'email',
          title: '邮箱',
          visible: false
        },
        {
          field: 'phonenumber',
          title: '手机'
        }]
    };
    $.table.init(options);

    $('#clearBtn').click(function (e) {
      $("#deptId").val('');
      $("#deptName").val('');
    });
  });

  function submitHandler(index, layero) {
      let loginNames = $.table.selectColumns("loginName");
      let userNames = $.table.selectColumnsRepeat("userName");
      $('#recipientName', window.parent.document).val(userNames.join(','));
      $('#recipient', window.parent.document).val(loginNames.join(','));
      $.modal.close();
  }

  function selectDeptTree() {
    var treeId = $("#deptId").val();
    var deptId = $.common.isEmpty(treeId) ? "100" : $("#deptId").val();
    var url = ctx + "system/dept/selectDeptTree/" + deptId;
    var options = {
      title: '选择部门',
      width: "380",
      url: url,
      callBack: doSubmit
    };
    $.modal.openOptions(options);
  }

  function doSubmit(index, layero){
    var tree = layero.find("iframe")[0].contentWindow.$._tree;
    var body = layer.getChildFrame('body', index);
    $("#deptId").val(body.find('#treeId').val());
    $("#deptName").val(body.find('#treeName').val());
    layer.close(index);
  }

  function resetForm() {
    $("#deptId").val('');
    $.form.reset();
  }
</script>
</body>
</html>